package ua.in.hut;

import java.io.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import ua.org.ass.*; 
import ua.org.ass.html.*;

/**
 *
 * @author frick.ua
 */
public class SrvTest extends HTTPServlet {

	@Override
	public void get(HttpServletRequest req, HttpServletResponse res) {
		try {
			//		try {
			RequestDispatcher rd = req.getRequestDispatcher("/test.html");
			req.setAttribute("test", "testAttribute");
			res.getWriter().append("<div><span>SrvTest label</span></div>");
			rd.forward(req, res);
//			res.sendRedirect("/test");
			/*res.setContentType("text/html");
			res.setCharacterEncoding("UTF-8");
			res.getWriter().append("<!DOCTYPE html>\r\n");
			HTMLElement doc = new HTMLElement("html");

			HTMLElement head = doc.addChild("head");
			head.addChild("link", "", "rel=\"stylesheet\" href=\"css/main.css\" type=\"text/css\"");
			head.addChild("title", "Hut;)");
			head.addChild("meta", "", "charset=\"UTF-8\"");
			//			head.addChild("meta", "", "name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"");
			head.addChild("meta", "", "name=\"viewport\" content=\"\\*width=device-width,*\\ initial-scale=1.0, user-scalable=no\"");
			//			head.addChild("script", "", "src=\"js/md5.js\"");
			//			head.addChild("script", "", "src=\"js/Login.js\"");
			//			head.addChild("script", "", "src=\"js/loginPanel.js\"");
			head.addChild("script", "", "src=\"js/registration.js\"");

			HTMLElement body = doc.addChild("body").setClass("body");
			HTMLElement mes = HMessage.createMessage();
			HTMLElement lDiv = new HTMLElement("div").setId("message-ldiv");
			HTMLElement rDiv = new HTMLElement("div").setId("message-rdiv");
			HTMLElement cDiv = new HTMLElement("div").setId("message-cdiv");
			cDiv.addChild(lDiv);
			cDiv.addChild(mes);
			cDiv.addChild(rDiv);
			body.addChild(cDiv);
			HTMLElement content = body.addChild("div").setClass("content").setId("content");
			HTMLElement title = content.addChild("div").setClass("title");
			title.addChild("span", "Це HUT.in.ua!").setClass("big shadowed");
			title.addChild("br");
			title.addChild("span", "Десь тут і Ваша майбутня хатинка:)");
			//			if (Authenticator.checkAuthentication(((HttpServletRequest) req).getCookies()., null, null)) {
			HTMLElement loginPanel = HLoginPanel.createLoginPanel();
			//			} else {
			//				HTMLElement loginPanel
			//			}
			head.addCssFilesLinks(loginPanel.getCssFiles());
			head.addScriptFilesLinks(loginPanel.getScriptFiles());
			content.addChild(loginPanel);
			doc.readHTML(res.getWriter());*/
//		} catch (IOException ex) {
//			Log.s(null, ex);
//		} catch (ServletException ex) {
//			Logger.getLogger(SrvTest.class.getName()).log(Level.SEVERE, null, ex);
//		}
			
			super.get(req, res);
		} catch (IOException ex) {
			Logger.getLogger(SrvTest.class.getName()).log(Level.SEVERE, null, ex);
		} catch (ServletException ex) {
			Logger.getLogger(SrvTest.class.getName()).log(Level.SEVERE, null, ex);
		}
	}

	private String getCookieValue(Cookie[] cookies, String name) {
		if (cookies != null) {

		}
		return null;
	}

}
